package com.wk.springboot.spring.controller;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;

/**
 * @User admin
 * @Date 2020/11/24 11:21
 **/
public class MyBeanNameGenerator implements BeanNameGenerator {
    @Override
    public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
        String beanName = null;
        //从beanDefinition中取出类名
        String beanClassName = definition.getBeanClassName();
        if (beanClassName.indexOf(".") != -1) {
            beanClassName = beanClassName.substring(beanClassName.lastIndexOf(".") + 1);
            //我们来添加一个前缀
            beanName = "dk_" + beanClassName;
        }
        return beanName;
    }
}
